package com.erbao.jmh;

import com.erbao.datastructurearithmetic.RandomUtil;

import java.util.LinkedList;
import java.util.List;

/**
 * @author CaoBaoYin
 * @since 22/3/9 14:39
 */
public class PS {

    private static List<Integer> list = new LinkedList<>();
    static {
        for (int i = 0; i < 1000000; i++) {
            list.add(RandomUtil.equalProbabilityInt(10000000));
        }
    }

    public static void forEachSingle() {
        list.forEach(PS::isPrime);
    }

    public static void parallelStream() {
        list.parallelStream().forEach(PS::isPrime);
    }

    private static boolean isPrime(Integer value) {
        for (int i = 0; i < value / 2; i++) {
            if (value % 2 == 0) return false;
        }
        return true;
    }
}
